<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){
	
	$params=array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'deleted'=>0);
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','ordersn','addressid','mid','paytype','createtime');
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			$realname=pdo_getcolumn('core_address',array('id'=>$item['addressid']),'name');
			$realname = $realname?$realname:'无收货人';
			$name=pdo_getcolumn('core_members',array('id'=>$item['mid']),'nickname');
			if(!$name){
				$name='匿名用户';
			}
			$goods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$item['id']),array('price','total','goodsid'));
			$item['total']=0;
			foreach($goods as &$v){
				$item['total'] +=$v['total'];
				$good=pdo_get('jy_weishop_goods',array('id'=>$v['goodsid']),array('title','image'));
				$return['list'][]=array('ordersn'=>$item['ordersn'],'createtime'=>date('Y-m-d H:i:s',$item['createtime']),'image'=>$good['image'],'title'=>$good['title'],'price'=>$v['price'],'total'=>$v['total'],'name'=>$name,'realname'=>$realname);
			}
			
		
		}
	}
	//$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'createtime','title'=>'下单时间','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'price','title'=>'单价','type'=>'string'),
			array('name'=>'total','title'=>'商品数量','type'=>'string'),
			array('name'=>'name','title'=>'会员名称','type'=>'string'),
			array('name'=>'realname','title'=>'收货人','type'=>'string'),
		)),
	
	);

	$return['htmls']=$htmls;
	
	exi($return);
}
